package ltaa.sponsoredsearch.GAM;

import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Arrays;

class Bidder {
	private int ID;
	private int numberOfItems;
	private double globalBudget;
	private double[] valuations;
	private double[] maxPrices;

	public Bidder(int ID, int items, double budget, double vals[], double	maxs[]) {
		this.ID = ID;
		this.numberOfItems = items;
		this.globalBudget = budget;
		this.valuations = vals.clone();
		this.maxPrices = maxs.clone();
	}

	public int getID() {return this.ID;}

	public double bid(int item) {return valuations[item];}

	public double max(int item) {return maxPrices[item];}

	public double getBudget() {return globalBudget;}
	
	public int getNumItems() {return numberOfItems;}

	public double getUtility(Map<Bidder, Set<Integer>> assignment, Map<Bidder, Double>
	prices) {
		double myAccVal = 0.0;
		if (assignment.containsKey(this)) {
			Set<Integer> myItems = assignment.get(this);
			Iterator it = myItems.iterator();
			int myItem;
			while (it.hasNext()) {
				Integer next = (Integer) it.next();
				myItem = next.intValue();
				myAccVal += valuations[myItem];
			}
		}
		double myPayment = 0.0;
		if (prices.containsKey(this)) 
			myPayment = prices.get(this).doubleValue();

		return myAccVal - myPayment;
	}

	public String toString() {
		return "("+ID+", "+numberOfItems+", "+globalBudget+", "+
		Arrays.toString(valuations)+", "+Arrays.toString(maxPrices)+")";
	}


}
